//
//  TacticsViewController.m
//  demo
//
//  Created by dllo on 15/7/11.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "TacticsViewController.h"
#import "GNViewController.h"
#import "GWViewController.h"

@interface TacticsViewController ()<UIScrollViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property (nonatomic, retain) UIScrollView *mainScrollView;
@property (nonatomic, retain) UILabel *lineLabel;
@property (nonatomic, retain) UISegmentedControl *seg;
@property (nonatomic, retain) UILabel *GNLabel;
@property (nonatomic, retain) UILabel *GWLabel;

@end

@implementation TacticsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"攻略";
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self setHeader];
    [self addMainScrollView];
    [self setGN];
    [self setGW];
    
}

- (void)setHeader
{
//    self.headItemView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width / 10)];
//    self.headItemView.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:_headItemView];
//
//    self.GNLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.headItemView.frame.size.width / 2, self.headItemView.frame.size.height)];
//    self.GNLabel.textAlignment = NSTextAlignmentCenter;
//    self.GNLabel.text = @"国外";
//    self.GNLabel.userInteractionEnabled = YES;
//    UITapGestureRecognizer *gnTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gnTap)];
//    gnTap.numberOfTapsRequired = 1;
//    [self.GNLabel addGestureRecognizer:gnTap];
//    self.GNLabel.textColor = [UIColor blueColor];
//    [self.headItemView addSubview:_GNLabel];
//    [_GNLabel release];
//    
//    self.GWLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.headItemView.frame.size.width / 2, 0, self.headItemView.frame.size.width / 2, self.headItemView.frame.size.height)];
//    self.GWLabel.text = @"国内";
//    self.GWLabel.textAlignment = NSTextAlignmentCenter;
//    self.GWLabel.userInteractionEnabled = YES;
//    UITapGestureRecognizer *gwTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gwTap)];
//    gwTap.numberOfTapsRequired = 1;
//    [self.GWLabel addGestureRecognizer:gwTap];
//    [self.headItemView addSubview:_GWLabel];
//    [_GWLabel release];
//    
//    self.lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.headItemView.frame.origin.y, self.headItemView.frame.size.width / 2, self.headItemView.frame.size.height)];
//    self.lineLabel.backgroundColor = [UIColor whiteColor];
//    self.lineLabel.alpha = 0.1;
//    [self.headItemView addSubview:self.lineLabel];
//    [_lineLabel release];
//    [_headItemView release];
    
    self.seg = [[UISegmentedControl alloc] initWithItems:@[@"国外", @"国内"]];
    self.seg.frame = CGRectMake(30, 10, self.view.frame.size.width - 60, 30);
    self.seg.tintColor = [UIColor colorWithRed:44 / 255.0 green:110 / 255.0 blue:125 / 255.0 alpha:1];
    [self.seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
    self.seg.selectedSegmentIndex = 0;
    [self.view addSubview:self.seg];
    [_seg release];
    
}

- (void)segAction:(UISegmentedControl *)seg
{
    if (seg.selectedSegmentIndex == 0) {
        self.mainScrollView.contentOffset = CGPointMake(0, 0);
    } else {
        self.mainScrollView.contentOffset = CGPointMake(self.view.frame.size.width, 0);
    }
}

- (void)addMainScrollView
{
    self.mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 50)];
    self.mainScrollView.showsVerticalScrollIndicator = NO;
    self.mainScrollView.delegate = self;
    self.mainScrollView.pagingEnabled = YES;
    self.mainScrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 0);
    [self.view addSubview:self.mainScrollView];
}

- (void)setGN
{
    GNViewController *gnVC = [[GNViewController alloc] init];
    gnVC.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    [self addChildViewController:gnVC];
    [self.mainScrollView addSubview:gnVC.view];
    [gnVC didMoveToParentViewController:self];
    [gnVC release];
}

- (void)setGW
{
    GWViewController *gwVC = [[GWViewController alloc] init];
    gwVC.view.frame = CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height - 64 * 3);
    [self addChildViewController:gwVC];
    [self.mainScrollView addSubview:gwVC.view];
    [gwVC didMoveToParentViewController:self];
    [gwVC release];
}

- (void)gnTap
{
    self.mainScrollView.contentOffset = CGPointMake(0, 0);
}

- (void)gwTap
{
    self.mainScrollView.contentOffset = CGPointMake(self.view.frame.size.width, 0);
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSInteger index =  scrollView.contentOffset.x / self.view.frame.size.width;
    if (index == 0) {
        self.seg.selectedSegmentIndex = 0;
    } else if (index == 1) {
        self.seg.selectedSegmentIndex = 1;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
